﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

namespace Filemanager
{
    public partial class Home : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["View"] = 1;
                if (Request.QueryString["Root"] == null)
                {
                    string root = Server.MapPath(ConfigurationManager.AppSettings["PathParent"]);
                    lbviewFile.Text = ViewThumb(root);
                }
                else
                {
                    string root = Server.MapPath(Request.QueryString["Root"]);
                    lbviewFile.Text = ViewThumb(root);
                }
            }
        }
        protected string ViewThumb(string root)
        {
            string s = "";
            Process pro = new Process();
            List<Folder> folderlist = new List<Folder>();
            pro.duyetThuMuc(root, folderlist);
            if (folderlist[0].ItemFolder.Count != 0)
            {
                for (int i = 0; i < folderlist[0].ItemFolder.Count; i++)
                {
                    s += "<li><a href=\"Viewthumb.aspx?root=" + folderlist[0].ItemFolder[i].URL + "\"><span>" +
                    "<img src=\"images/icons/finefiles/64/_Open.png\" width=\"64\" height=\"45\" class=\"thumb\"></span>";
                    s += folderlist[0].ItemFolder[i].Name;
                    s += "</a></li>";
                }
            }
            if (folderlist[0].File.Count != 0)
            {
                for (int i = 0; i < folderlist[0].File.Count; i++)
                {
                    if (pro.GetExtenFile(pro.cutName(folderlist[0].File[i])) != "jpg")
                    {
                        s += "<li id=\"fileitem" + i + "\"><a href=\"#\" oncontextmenu=\"RightClick(" + i + ")\"><span>" +
                    "<img src=\"images/icons/finefiles/64/" + pro.GetExtenFile(pro.cutName(folderlist[0].File[i])) + ".png\" width=\"64\" height=\"45\" class=\"thumb\"></span>";
                        s += pro.cutName(folderlist[0].File[i]);
                        s += "</a></li>";
                    }
                    else
                    {
                        s += "<li id=\"fileitem" + i + "\"><a href=\"#\" oncontextmenu=\"RightClick(" + i + ")\"><span>" +
                    "<img src=\"" + folderlist[0].File[i] + "\" width=\"64\" height=\"45\" class=\"thumb\"></span>";
                        s += pro.cutName(folderlist[0].File[i]);
                        s += "</a></li>";
                    }
                }
            }
            return s;
        }
    }
}